package com.company.woye.boxmanagerdetail.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.company.woye.R;
import com.company.woye.base.BaseActivity;
import com.company.woye.boxmanagerdetail.adapter.InefficiencyNumberListViewAdapter;
import com.company.woye.console.adapter.*;

import butterknife.BindView;
import butterknife.OnClick;

public class BoxManagerDetailActivity extends BaseActivity {
    @BindView(R.id.lv_box_operation_summary)
    ListView summaryListView;

    @BindView(R.id.ll_box_operation_summary)
    LinearLayout summaryLinearLayout;


    @BindView(R.id.tv_box_operation_summary)
    TextView summaryTextView;

    @BindView(R.id.lv_box_operation_detail)
    ListView detailListView;

    @BindView(R.id.ll_box_operation_detail)
    LinearLayout detailLinearLayout;

    @BindView(R.id.tv_box_operation_detail)
    TextView detailTextView;

    @BindView(R.id.lv_box_operation_number)
    ListView numberListView;

    @BindView(R.id.ll_box_operation_number)
    LinearLayout numberLinearLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setLayoutId() {
        return R.layout.activity_box_manager_detail;
    }

    @Override
    public void initView() {
        summaryListView.setAdapter(new BoxOperationListviewAdapter(this));

    }
    @OnClick({R.id.iv_box_operation_back, R.id.tv_box_operation_summary, R.id.tv_box_operation_detail})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.iv_box_operation_back:
                finish();
                break;
            case R.id.tv_box_operation_summary:
                summaryTextViewOnClick();
                break;
            case R.id.tv_box_operation_detail:
                detailTextViewOnClick();
                break;
        }
    }

    private void summaryTextViewOnClick() {
        summaryLinearLayout.setVisibility(View.VISIBLE);
        detailLinearLayout.setVisibility(View.GONE);
        numberLinearLayout.setVisibility(View.GONE);
        numberListView.setVisibility(View.GONE);
        summaryListView.setAdapter(new BoxOperationListviewAdapter(this));
        summaryTextView.setTextColor(getResources().getColor(R.color.blue));
        detailTextView.setTextColor(getResources().getColor(R.color.darkGray));
    }


    private void detailTextViewOnClick() {
        summaryLinearLayout.setVisibility(View.GONE);
        detailListView.setAdapter(new InefficiencyNumberListViewAdapter(this));
        detailLinearLayout.setVisibility(View.VISIBLE);
        summaryTextView.setTextColor(getResources().getColor(R.color.darkGray));
        detailTextView.setTextColor(getResources().getColor(R.color.blue));
    }

    private void showPopupWindow() {
        View view = LayoutInflater.from(this).inflate(R.layout.popupwindow_out_bound, null);
        final PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ImageView back = view.findViewById(R.id.iv_out_bound_back);
        TextView pause = view.findViewById(R.id.tv_pop_pause);
        TextView resume = view.findViewById(R.id.tv_pop_resume);
        back.setOnClickListener(v -> {
            popupWindow.dismiss();
        });
        pause.setOnClickListener(v -> pause.setBackgroundResource(R.drawable.button_yellow_shape));

        resume.setOnClickListener(v -> pause.setBackgroundResource(R.drawable.button_primary_shape));
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
    }
}
